Conversation
📝 WalkthroughWalkthroughThe pipload package is migrated from the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
R/OLD_pip_load_aux.R (1)
362-385:⚠️ Potential issue | 🟠 Major
find_path()can throw index errors before the intended not-found abort.At Line 368,
ext_order[[i]]is accessed in an unboundedwhileloop. If no extension matches,iexceedslength(ext_order)and errors before Line 379’scli_abort.🔧 Proposed fix
find_path <- function(file_paths) { extensions <- fs::path_ext(file_paths) ext_order <- c("qs2", "fst", "rds", "dta") - f <- FALSE - i <- 1 - while (f == FALSE) { - - ext <- ext_order[[i]] - - if(ext %in% extensions) { - p <- which(extensions == ext) - f <- file_paths[[p]] - } else { - i <- i + 1 - } - - } - - if (f == FALSE) { - msg <- c( - "File not found", - "*" = "At least one of the following extension should be available: {.file {ext_order}}" - ) - cli::cli_abort(msg, - class = "error_class") - } - - return(f) + for (ext in ext_order) { + if (ext %in% extensions) { + p <- which(extensions == ext)[1] + return(file_paths[[p]]) + } + } + + msg <- c( + "File not found", + "*" = "At least one of the following extensions should be available: {.file {ext_order}}" + ) + cli::cli_abort(msg, class = "error_class") }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@R/OLD_pip_load_aux.R` around lines 362 - 385, The while loop using ext_order[[i]] can run past the end and throw an index error before the intended cli_abort; fix by bounding the loop (e.g., replace the unbounded while with a for loop over ext_order or change the while condition to while(!f && i <= length(ext_order))) so you never call ext_order[[i]] out-of-range, using the existing variables ext_order, extensions, file_paths, f and i and keeping the post-loop cli::cli_abort when no match is found.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@R/OLD_pip_load_aux.R`:
- Around line 334-343: The read_by_format branch leaves x NULL when pformat is
unrecognized; update read_by_format (the branch that sets x based on pformat) to
explicitly error when pformat is not one of the supported values ("qs2", "fst",
"rds", "dta") by calling abort/stop with a clear message that includes the
invalid pformat and the allowed formats so the function fails fast instead of
returning NULL.
---
Outside diff comments:
In `@R/OLD_pip_load_aux.R`:
- Around line 362-385: The while loop using ext_order[[i]] can run past the end
and throw an index error before the intended cli_abort; fix by bounding the loop
(e.g., replace the unbounded while with a for loop over ext_order or change the
while condition to while(!f && i <= length(ext_order))) so you never call
ext_order[[i]] out-of-range, using the existing variables ext_order, extensions,
file_paths, f and i and keeping the post-loop cli::cli_abort when no match is
found.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 471de3d8-8869-4b0c-ad8c-f909fa58f889
📒 Files selected for processing (13)
DESCRIPTIONNAMESPACER/OLD_pip_load_aux.RR/load_dlw_data.RR/load_pip_data.RR/pip_load_all_aux.RR/pip_merge_aux.Rman/aux_ids.Rdman/load_dlw_data.Rdman/load_pip_data.Rdman/pip_load_aux.Rdman/pip_merge_aux.Rdvignettes/read_write_pins.Rmd
| x <- | ||
| if (pformat == "qs") { | ||
|
|
||
| qs::qread(file_to_load) | ||
|
|
||
| } else if (pformat == "fst") { | ||
|
|
||
| if (pformat == "qs2") { | ||
| qs2::qs_read(file_to_load) | ||
| } else if (pformat == "fst") { | ||
| fst::read_fst(file_to_load, as.data.table = TRUE) | ||
|
|
||
| } else if (pformat == "rds") { | ||
|
|
||
| readr::read_rds(file_to_load) | ||
|
|
||
| } else if (pformat == "dta") { | ||
|
|
||
| haven::read_dta(file_to_load) | ||
| } |
There was a problem hiding this comment.
Unsupported extensions are not rejected explicitly in read_by_format().
If pformat is unknown, x is left NULL and returned silently, which can fail later in less obvious ways. Fail fast with a clear abort at the read boundary.
🔧 Proposed fix
read_by_format <- function(file_to_load) {
pformat <- fs::path_ext(file_to_load)
x <-
if (pformat == "qs2") {
qs2::qs_read(file_to_load)
} else if (pformat == "fst") {
fst::read_fst(file_to_load, as.data.table = TRUE)
} else if (pformat == "rds") {
readr::read_rds(file_to_load)
} else if (pformat == "dta") {
haven::read_dta(file_to_load)
+ } else {
+ cli::cli_abort(c(
+ "Unsupported file format",
+ x = "Extension {.field {pformat}} is not supported.",
+ i = "Supported formats: {.field {c('qs2', 'fst', 'rds', 'dta')}}"
+ ), class = "pipload_error")
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@R/OLD_pip_load_aux.R` around lines 334 - 343, The read_by_format branch
leaves x NULL when pformat is unrecognized; update read_by_format (the branch
that sets x based on pformat) to explicitly error when pformat is not one of the
supported values ("qs2", "fst", "rds", "dta") by calling abort/stop with a clear
message that includes the invalid pformat and the allowed formats so the
function fails fast instead of returning NULL.
Hi @RossanaTat,
Here is the PR to fix the issue of
load_pip_dataand it also fixes some stuff with the examples that were affecting the check. Let me know what you think, especially for the "aux" functions. Thank you for reviewing!Summary by CodeRabbit
New Features
Updates
Documentation